package com.coco.expressfee.service.impl;

import com.coco.expressfee.mapper.ExpressFeeMapper;
import com.coco.expressfee.pojo.TbPostage;
import com.coco.expressfee.service.ExpressFeeService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 服务实现层
 * @author Administrator
 *
 */
@Service
public class GoodsServiceImpl implements ExpressFeeService {

    @Autowired
    private ExpressFeeMapper expressFeeMapper;

    /**
     * 增加
     */
    @Override
    public void add(TbPostage goods) {
        expressFeeMapper.insert(goods);
    }

    /**
     * 批量删除
     */
    @Override
    public void delete(Long[] ids) {
        for(Long id:ids){
            expressFeeMapper.deleteByPrimaryKey(id);
        }
    }

    /**
     * 修改
     */
    @Override
    public void update(TbPostage goods){
        expressFeeMapper.updateByPrimaryKey(goods);
    }


    /**
     * 根据ID获取实体
     * @param id
     * @return
     */
    @Override
    public TbPostage findOne(Long id){
        return expressFeeMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询全部
     */
    @Override
    public List<TbPostage> findAll() {
        return expressFeeMapper.findAll();
    }

    /**
     * 查询全部带条件
     */
    @Override
    public List<TbPostage> findAll(TbPostage goods) {
        return expressFeeMapper.selectByExample(goods);
    }

    /**
     * 分页模糊
     */
    @Override
    public List<TbPostage> findAllSearch(TbPostage tbPostage) {
        PageHelper.startPage(tbPostage.getPage(),tbPostage.getLimit());
        return expressFeeMapper.selectByExample(tbPostage);
    }

    /**
     * 根据商品id查询运费模板
     * @param gid
     * @return
     */
    @Override
    public List<TbPostage> findByGid(String gid) {
        return expressFeeMapper.findByGid(gid);
    }

    /**
     * 根据gid删除
     * @param gid
     */
    @Override
    public void deleteByGid(String gid) {
        expressFeeMapper.deleteByGid(gid);
    }
}

